package config;

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class Config {
	private static final String[] fonts = {"interstate","arial"};
	private static final String footerLinkDirection = "left";
	private static final String[] footerLinks = {"terms & conditions" , "privacy" , "security","careers","about us","contact us"};
	private static final String[] socialMediaLinks = {"facebook" , "twitter"};
	private static final String[] googleAnalytics = {"analytics.js","ga.js"};
	private static final String phantomJsPath = "phantomjs --ssl-protocol=any";
	private static final String jsonConfigFilePath = "/Volumes/E_Drive/node/citi/";
	private static final String jsonConfigFileName = "jsonConfig.js";
	private static final String jQueryPath = "http://code.jquery.com/jquery-1.11.0.min.js";
	
	public static String[] getFonts() {
		return fonts;
	}
	public static String getFooterlinkdirection() {
		return footerLinkDirection;
	}
	public static String[] getFooterlinks() {
		return footerLinks;
	}
	public static String[] getSocialmedialinks() {
		return socialMediaLinks;
	}
	public static String[] getGoogleanalytics() {
		return googleAnalytics;
	}
	public static String getPhantomjspath() {
		return phantomJsPath;
	}
	
	public static String getJsonConfigFileName() {
		return jsonConfigFileName;
	}
	
	@SuppressWarnings("unchecked")
	private static String getConfigInJSON(){
		JSONObject jsonConfig = new JSONObject();
		jsonConfig.put("footerLinkDirection", footerLinkDirection);
		jsonConfig.put("jquerypath", jQueryPath);
		JSONArray fontList = new JSONArray();
		for(int i = 0 ; i < fonts.length ; i ++){
			fontList.add(fonts[i]);
		}
		jsonConfig.put("fonts", fontList);
		
		JSONArray footerLinksList = new JSONArray();
		for(int i = 0 ; i < footerLinks.length ; i ++){
			footerLinksList.add(footerLinks[i]);
		}
		jsonConfig.put("footerLinks", footerLinksList);

		JSONArray socialMediaLinksList = new JSONArray();
		for(int i = 0 ; i < socialMediaLinks.length ; i ++){
			socialMediaLinksList.add(socialMediaLinks[i]);
		}
		jsonConfig.put("socialMediaLinks", socialMediaLinksList);
		
		JSONArray googleAnalyticsList = new JSONArray();
		for(int i = 0 ; i < googleAnalytics.length ; i ++){
			googleAnalyticsList.add(googleAnalytics[i]);
		}
		jsonConfig.put("googleAnalytics", googleAnalyticsList);		
		return jsonConfig.toJSONString();
	}
	
	public static void createJSONConfig() throws FileNotFoundException, UnsupportedEncodingException{
		PrintWriter writer = new PrintWriter(jsonConfigFilePath + jsonConfigFileName, "UTF-8");
		writer.print("var config=");
		writer.println("JSON.parse('" + getConfigInJSON() + "')");
		writer.close();
	}
	
}
